/*********************************************************************
 * PrimeUtil.java created on Feb 26, 2010
 *
 * This file is part of Sure Tech Support Portal System. 
 * Copyright @ 2010 Sure Tech (HK) Limited. All rights reserved.
 * Sure Tech PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 *********************************************************************/
package demo.concurrent.primefinder;

import java.math.BigInteger;

/**
 * @Author: Mac Wang
 * @Date: Feb 26, 2010 9:56:19 AM 
 * @Email: mac@suretech.com.hk
 */

public class PrimeUtil {
	public static BigInteger findFirstPrime(long lowerBound, long upperBound)
	{
		BigInteger result;
		BigInteger startPos = BigInteger.valueOf(lowerBound);
		BigInteger nextProblePrime;
		
		if(startPos.isProbablePrime(32))
			nextProblePrime = startPos;
		else
			nextProblePrime = startPos.nextProbablePrime();
		
		if(nextProblePrime.longValue() >= upperBound)
			result = null;
		else
			result = nextProblePrime;
		
		return result;
	}
}
